package com.qfmy.app.service.impl.user;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;

import com.qfmy.app.service.user.SsmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author 清风明月
 * @Package com.qfmy.app.service.impl.user
 * @date 2025/4/13
 * @description 短信验证码
 */
@Slf4j
@Service
@SuppressWarnings("all")
public class SsmServiceImpl implements SsmService {

    /**
     * 注入短信服务
     */
    @Autowired
    private Client client;

    /**
     * 发送短信验证码
     * @param phone
     */
    @Override
    public void sendSmsCode(String phone,String code) {
        try {
            // 创建短信发送请求对象
            SendSmsRequest sendSmsRequest = new SendSmsRequest();
            // 设置接收验证码的手机号码
            sendSmsRequest.setPhoneNumbers(phone);
            // 设置短信签名名称
            sendSmsRequest.setSignName("阿里云短信测试");
            // 设置短信模板编号
            sendSmsRequest.setTemplateCode("SMS_154950909");
            // 设置短信模板参数，将验证码作为参数传入
            sendSmsRequest.setTemplateParam("{\"code\":\"" + code + "\"}");
            // 发送短信
            client.sendSms(sendSmsRequest);
        } catch (Exception e) {
            log.error("发送短信验证码失败", e.getCause());
        }
    }
}
